package guiobjects;

import java.awt.Color;
import java.util.Scanner;

/**
 * draws some text.
 * 
 * @author Trevor Terris
 *
 */
public class Text implements IPaintedObject {
	private String myText = "";
	private double myXCoord = 0;
	private double myYCoord = 0;
	private String myLocation = "bottom";
	public void parseText(String input)
	{
		Scanner s = new Scanner(input);
		if (!s.hasNextDouble())
			myLocation = s.next();
		myXCoord = s.nextDouble();
		myYCoord = s.nextDouble();
		myText = s.nextLine();
	}
	public void drawObject(java.awt.Graphics pen, int screenWidth, int screenHeight, int offset)
	{
		int heightOffset = -1;
		if (myLocation.compareTo("middle") == 0)
			heightOffset = 5;
		if (myLocation.compareTo("top") == 0)
			heightOffset = 11;
		pen.setColor(Color.BLACK);
		pen.drawString(myText, (int)(myXCoord * screenWidth) + offset, (int)(myYCoord * screenHeight) + heightOffset);
	}
	public String getSVGData(int width, int offset, int total)
	{
		String positioning = "style=\"fill:rgb(0,0,0);\"";
		if (myLocation.compareTo("middle") == 0)
			positioning =  "style=\"dominant-baseline: central;fill:rgb(0,0,0);\"";
		if (myLocation.compareTo("top") == 0)
			positioning =  "style=\"dominant-baseline: hanging;fill:rgb(0,0,0);\"";
		double xValue = (((double)offset + (double)width * myXCoord) * 100.0 / (double) total);
		double yValue = myYCoord * 100.0;
		return "<text x=\""+xValue+"%\" y=\""+yValue+"%\" " + positioning + ">" + myText + "</text>";
	}
}
